package com.yy.base.page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.yy.base.util.SessionInfo;

@SuppressWarnings("unchecked")
public class Message extends HashMap {
	private static final long serialVersionUID = 1L;
	public void put(String key, Object value) {
		this.setData(key, value);
	}
	public void setMsg(String msg) {
		this.put("msg", msg);
	}
	public void setData(String key, Object value) {
		super.put("result", true);
		super.put(key, value);
	}
	public void setData(Map data) {
		super.put("result", true);
		if(null != data) {
			this.putAll(data);
		}
	}
	public void setErrorMessage(String msg) {
		super.put("msg", msg);
		super.put("result", false);
		super.put("status", "error");
	}
	public void setOkMessage(String msg) {
		super.put("msg", msg);
		super.put("result", true);
		super.put("status", "ok");
	}
	public void formartData(Object obj) {
		super.put("result", true);
		super.put("status", "ok");
		if (obj != null && obj instanceof String) {
			super.put("msg", obj);
		} else {
			super.put("data", obj);
		}
	}
	/**
	 * 格式成表格数据
	 */
	public void setPageList(List list) {
		super.put("rows", list);
		Page page = SessionInfo.getPage();
		if (page != null) {
			super.put("total", page.getTotal());
		}
	}
	/**
	 * 格式成表格数据
	 */
	public void setSplitPageList(List list) {
		super.put("data", list);
		super.put("code", 0);
		Page page = SessionInfo.getPage();
		if (page != null) {
			super.put("count", page.getTotal());
		}
	}
}
